package com.quanyan.stadiumScheduler.service.impl;

import com.quanyan.club.service.ClubOpenService;
import com.quanyan.common.utils.ObjectUtil;
import com.quanyan.stadiumScheduler.biz.redis.DefaultConfigCacheDao;
import com.quanyan.stadiumScheduler.entity.TbGameCommonParameter;
import com.quanyan.stadiumScheduler.mapper.TbGameCommonParameterMapper;
import com.quanyan.stadiumScheduler.constants.GameConstants;
import com.quanyan.stadiumScheduler.entity.TbGameCommonParameterExample;
import com.quanyan.stadiumScheduler.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lds
 * @date 2017/2/14 11:35
 *
 * 该类存放一些公用方法,方便本模块中的方法使用,获取外部模块提供的方法,均从改模块出
 */

@Service
public class BaseServiceImpl implements BaseService {

    @Autowired
    private ClubOpenService clubOpenService;

    @Autowired
    private TbGameCommonParameterMapper tbGameCommonParameterMapper;

    @Autowired
    private DefaultConfigCacheDao defaultConfigCacheDao;

    @Override
    public TbGameCommonParameter queryTbGameCommonParameter(String paramGroupKey, String paramKey) {
        List<TbGameCommonParameter> result = defaultConfigCacheDao.getTbGameCommonParameterListMsgFromCache(paramGroupKey);
        if (result == null || result.size() < 1) {
            TbGameCommonParameterExample example = new TbGameCommonParameterExample();
            TbGameCommonParameterExample.Criteria criteria = example.createCriteria();
            criteria.andParameterGroupEqualTo(paramGroupKey);
            criteria.andIsDeleteEqualTo(GameConstants.IS_NOT_DELETE);
            result = tbGameCommonParameterMapper.selectByExample(example);
            defaultConfigCacheDao.initTbGameCommonParameterMsgToCache(paramGroupKey, result);
        }
        if (ObjectUtil.isNotObjectEmpty(result)) {
            for (TbGameCommonParameter tbGameCommonParameter:result) {
                if (tbGameCommonParameter.getParameterKey().equals(paramKey)) {
                    return tbGameCommonParameter;
                }
            }
        }
        return null;
    }

    @Override
    public Map<Integer, List<Integer>> queryClubIds(List<Integer> clubs) {
        Map<Integer, List<Integer>> result = new HashMap<>();
        if (null == clubs || clubs.size() < 1) {
            return result;
        }
        try{
            result = clubOpenService.getClubsTeamMembersId(clubs);
        }catch (Exception e) {
            result = new HashMap<>();
        }finally {
            return result;
        }
    }



}
